﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACEPAPI
{
    /// <summary>
    /// 打印机自动状态回传
    /// </summary>
    public class ABSStatus
    {
        private byte[] Buffer;
        public ABSStatus(byte[] bytes)
        {
            //固定Bit3=Buffer[3]=0x0F=0b_0000_1111;
            Buffer = new byte[4];
            Array.Copy(bytes, Buffer, 4);
        }
        //  Bit0-0 固定 0

        //  Bit0-1 固定 0

        /// <summary>
        /// Bit0-2 抽屉是否打开
        /// </summary>
        public bool DrawerStatus => (Buffer[0] & 0b_0000_0100) != 0;

        /// <summary>
        /// Bit0-3 打印机是否在线
        /// </summary>
        public bool PrinterOnline => (Buffer[0] & 0b_0000_1000) == 0;

        //  Bit0-4 固定 1

        /// <summary>
        /// Bit0-5 是否纸盖已打开
        /// </summary>
        public bool PaperCover => (Buffer[0] & 0b_0010_0000) != 0;

        /// <summary>
        /// Bit0-6 是否正在通过进纸按钮进纸
        /// </summary>
        public bool ButtonPaper => (Buffer[0] & 0b_0100_0000) != 0;

        //  Bit0-7 固定 0

        /// <summary>
        /// Bit1-0 是否正在等待在线恢复
        /// </summary>
        public bool WaitOnlineRecovery => (Buffer[1] & 0b_0000_0001) != 0;

        /// <summary>
        /// Bit1-1 是否按下了进纸按钮
        /// </summary>
        public bool ButtonPaperFeed => (Buffer[1] & 0b_0000_0010) != 0;

        /// <summary>
        /// Bit1-2 是否发生可恢复的错误(自动裁纸器错误除外)
        /// </summary>
        public bool ErrorRecoverable => (Buffer[1] & 0b_0000_0100) != 0;

        /// <summary>
        /// Bit1-3 是否自动裁纸器发生错误
        /// </summary>
        public bool ErrorAutocutter => (Buffer[1] & 0b_0000_1000) != 0;

        //  Bit1-4 固定 0

        /// <summary>
        /// Bit1-5 是否发生不可恢复的错误
        /// </summary>
        public bool ErrorUnrecoverable => (Buffer[1] & 0b_0010_0000) != 0;

        /// <summary>
        /// Bit1-6 是否有可自动恢复的错误
        /// </summary>
        public bool ErrorAutoRecoverable => (Buffer[1] & 0b_0100_0000) != 0;

        //  Bit1-7 固定 0

        /// <summary>
        /// Bit2-0,1 是否纸张即将用尽
        /// </summary>
        public bool PaperNearEnd => (Buffer[2] & 0b_0000_0011) != 0;

        /// <summary>
        /// Bit2-2,3 是否纸张用尽
        /// </summary>
        public bool PaperNot => (Buffer[2] & 0b_0000_1100) != 0;

        //  Bit2-4 固定 0
        //  Bit2-5 保留
        //  Bit2-6 保留
        //  Bit2-7 固定 0
        //  Bit3   固定0b00001111=0x0F
        
    }
}
